package sample.Utils;

import javafx.scene.canvas.GraphicsContext;
import sample.Shapes.ArrowLine;
import sample.Shapes.Circle;
import sample.Shapes.Ellipse;

import java.util.List;

public class RedrawUtils {

    // 重新绘制所有元素
    public static List<Object> redraw(GraphicsContext gc,List<Object> totalList,List<ArrowLine> arrowLines,List<Circle> circles,
                                      List<Ellipse> ellipses) {
        gc.clearRect(0, 0, 1000, 600); // 清除画布

        for (int i = 0; i < totalList.size(); i++) {
            if(((List<Circle>)totalList.get(i)).get(0) instanceof Circle){
                circles= (List<Circle>) totalList.get(i);
                for (int ii = 0; ii <circles.size(); ii++) {
                    circles.get(ii).draw(gc,circles.get(ii).x,circles.get(ii).y,circles.get(ii).w,circles.get(ii).h);
                }
            }
        }

        for (int i = 0; i < totalList.size(); i++) {
            if(((List<Ellipse>)totalList.get(i)).get(0) instanceof Ellipse){
                ellipses= (List<Ellipse>) totalList.get(i);
                for (int ii = 0; ii <ellipses.size(); ii++) {
                    ellipses.get(ii).draw(gc,ellipses.get(ii).x,ellipses.get(ii).y,ellipses.get(ii).w,ellipses.get(ii).h);
                }
            }
        }

        for (int i = 0; i < totalList.size(); i++) {
            if(((List<ArrowLine>)totalList.get(i)).get(0) instanceof ArrowLine){
                arrowLines= (List<ArrowLine>) totalList.get(i);
                for (int ii = 0; ii <arrowLines.size(); ii++) {
                    arrowLines.get(ii).draw(gc,arrowLines.get(ii).lineStartX,arrowLines.get(ii).lineStartY,arrowLines.get(ii).lineEndX,arrowLines.get(ii).lineEndY);
                }
            }
        }



        totalList.clear();
        totalList.add(circles);
        totalList.add(arrowLines);
        totalList.add(ellipses);
        return totalList;
    }
}
